﻿using Net.Event;
using Net.Helper;
using System.Runtime.CompilerServices;

namespace ApplicationCrashTesting
{
    internal class Program
    {
        static unsafe void Main(string[] args)
        {
            NDebug.WriteFileMode = WriteLogMode.All;
            NDebug.BindConsoleLog();
            ApplicationHelper.CrashRecovery();
            NDebug.Log("输入test1,2,3测试崩溃重启! --崩溃信息在log文件中");
            while (true)
            {
                var cmd = Console.ReadLine();
                if (cmd == "test1")
                {
                    throw new Exception("程序崩溃测试");
                }
                if (cmd == "test2")
                {
                    void* p = null;
                    Unsafe.WriteUnaligned(p, 1);
                }
                if (cmd == "test3")
                {
                    Thread thread = new Thread(() =>
                    {
                        try
                        {
                            byte[] bytes = new byte[1024];
                            void* p = Unsafe.AsPointer(ref bytes[0]);
                            void* p1 = Unsafe.AsPointer(ref bytes[0]);
                            Unsafe.CopyBlockUnaligned(p, p1, 10000);
                        }
                        catch(Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    });
                    thread.Start();
                }
            }
        }
    }
}
